#pragma once

#include <process.h>
#include <comutil.h>
#include "Pipe.h"

#pragma pack(1)
typedef struct _Msg_head
{
	UINT32 type;
	UINT32 length;
}Msg_head;
#pragma pack()


enum TransferProtocol
{
	RunCommand = 1,
	SendPicture,
	SendApk,
	BackupWechat,
	RestoreWechat,
	GetSetting,
	SetProps,
	BootSystem,
};


class Msg
{
public:

	Msg(wchar_t *pipename, wchar_t *jsonsetting);
	~Msg(void);

	bool m_bIsCanUseInput;
	void SendMsg(UINT32 type, std::wstring msg);
	void ReadMsg();

private:
	HANDLE _pipeSeverWriteEvent;
	HANDLE _pipeSeverReadEvent;
	HANDLE _pipeSeverEndEvent;
	static void _cdecl LoopThread(void * pThis);
	void WaitPipeClientEnd();
	void SendJSON();
	CRITICAL_SECTION m_csInput;
	bool m_isLoop = true;
	wchar_t m_Json_setting[4096];
	wchar_t m_pcInputValue[1024];
	Pipe * m_pipe;
};